function update_page(total_page,current_page,father,pagesize)
 {
     var total_page = parseInt( total_page );
     var current_page = parseInt( current_page );
     var pager_length = 11;    //不包next 和 prev 必须为奇数
     var pager = new Array( pager_length );
     var header_length = 2; 
     var tailer_length = 2;
     //header_length + tailer_length 必须为偶数
     var main_length = pager_length - header_length - tailer_length; //必须为奇数
     
     var a_tag = 'li';
     var a_class = '';
     var a_id = '';
     var a_name = '';
     
     var disable_class = 'disable';
     var select_class = 'select';
                 
     var i;
     var code = '';
	 
     if( total_page < current_page )
     {
         alert('已经是最后一页');
         return false;    
     }    
     //判断总页数是不是小于 分页的长度，若小于则直接显示
     if( total_page < pager_length )
     {
         for(i = 0; i <     total_page; i++)
         {
             
             code += (i+1 != current_page) ? fill_tag(a_tag, a_class, a_id, a_name, i+1,pagesize,total_page) : fill_tag(a_tag, select_class, a_id, a_name, i+1,pagesize,total_page);
         }
     }
     //如果总页数大于分页长度，则为一下函数
     else
     {
         //先计算中心偏移量
         var offset = ( pager_length - 1) / 2;
         //分三种情况，第一种左边没有...
         if( current_page <= offset + 1)
         {
             var tailer = '';
             //前header_length + main_length 个直接输出之后加一个...然后输出倒数的    tailer_length 个
             for( i = 0; i < header_length + main_length; i ++)
                 code += (i+1 != current_page) ? fill_tag(a_tag, a_class, a_id, a_name, i+1,pagesize,total_page) : fill_tag(a_tag, select_class, a_id, a_name, i+1,pagesize,total_page);
             code += fill_tag(a_tag, a_class, a_id, a_name, '...',pagesize,total_page);
             for(i = total_page; i > total_page - tailer_length; i --)
                 tailer = fill_tag(a_tag, a_class, a_id, a_name, i,pagesize,total_page) + tailer;
                 
             code += tailer;
         }
         //第二种情况是右边没有...
         else if( current_page >= total_page - offset )
         {
             var header = '';
             //后tailer_length + main_length 个直接输出之前加一个...然后拼接 最前面的 header_length 个
             for( i = total_page; i >= total_page-main_length - 1; i --)
                 code = (( current_page != i ) ? fill_tag(a_tag, a_class, a_id, a_name, i,pagesize,total_page) : fill_tag(a_tag, select_class, a_id, a_name, i,pagesize,total_page)) + code;
             code = fill_tag(a_tag, a_class, a_id, a_name, '...',pagesize,total_page) + code;
             for( i = 0; i < header_length ; i++)
                 header +=  fill_tag(a_tag, a_class, a_id, a_name, i + 1,pagesize,total_page);
             
             code = header + code;
         }
         //最后一种情况，两边都有...
         else
         {
             var header = '';
             var tailer = '';
             //首先处理头部
             for( i = 0; i < header_length; i ++)
                 header += fill_tag(a_tag, a_class, a_id, a_name, i + 1,pagesize,total_page);
             header += fill_tag(a_tag, a_class, a_id, a_name, '...',pagesize,total_page);
             //处理尾巴
             for(i = total_page; i > total_page - tailer_length; i --)
                 tailer = fill_tag(a_tag, a_class, a_id, a_name, i,pagesize,total_page) + tailer;
             tailer = fill_tag(a_tag, a_class, a_id, a_name, '...',pagesize,total_page) + tailer;
             //处理中间
             //计算main的中心点
             var offset_m = ( main_length - 1 ) / 2;
             var partA = '';
             var partB = '';
             var j;
             var counter = (parseInt(current_page) + parseInt(offset_m));
             for(i = j = current_page ; i <= counter; i ++, j --)
             {
                 partA = (( i == j ) ? '' : fill_tag(a_tag, a_class, a_id, a_name, j,pagesize,total_page)) + partA;
                 partB += ( i == j ) ? fill_tag(a_tag, select_class, a_id, a_name, i,pagesize,total_page) : fill_tag(a_tag, a_class, a_id, a_name, i,pagesize,total_page);
             }
             //拼接
             code = header + partA + partB + tailer;
             
             
         }
     }
     
     
     var prev = ( current_page == 1 ) ? fill_tag(a_tag, disable_class, a_id, a_name, 'prev',pagesize,total_page) : fill_tag(a_tag, a_class, a_name, a_name, 'prev',pagesize,total_page);
     var next = ( current_page == total_page ) ? fill_tag(a_tag, disable_class, a_id, a_name, 'next',pagesize,total_page) : fill_tag(a_tag, a_class, a_name, a_name, 'next',pagesize,total_page);
     code = prev + code + next;
     document.getElementById(father).innerHTML=(code);
 }
 
 function fill_tag(a_tag, a_class, a_id, a_name, a_html,pagesize,total_page)
 {
     a_class = (a_class == '') ? '' : ' class="'+a_class+'"';
     a_id = (a_id == '') ? '' : ' id="'+a_id+'"';
     a_name = (a_name == '') ? '' : ' name="'+a_name+'"';
     
     var code;
     
     if(!isNaN(parseInt(a_html))){
    	 code = '<'+a_tag+a_class+a_id+a_name+' >'+'<a href="javascript:void(0);" onclick="go('+a_html+','+pagesize+','+total_page+')">'+a_html+'</a>'+'</'+a_tag+'>';
     }
     else if(a_html=="next"){
    	 code = '<'+a_tag+a_class+a_id+a_name+' >'+'<a href="javascript:void(0);" onclick="next('+a_html+','+pagesize+','+total_page+')">'+a_html+'</a>'+'</'+a_tag+'>';
     }
     else if(a_html=="prev"){
    	 code = '<'+a_tag+a_class+a_id+a_name+' >'+'<a href="javascript:void(0);" onclick="prev('+a_html+','+pagesize+','+total_page+')">'+a_html+'</a>'+'</'+a_tag+'>';
     }
     else if(a_html=="..."){
    	 code = '<'+a_tag+a_class+a_id+a_name+' >'+'<a href="javascript:void(0);">'+a_html+'</a>'+'</'+a_tag+'>';
     }
     
     return code;
 }
 
 
function go(index,pagesize,total_page)
{
	
	//alert("index=="+index+"  pagesize=="+pagesize+"  total_page=="+total_page);
	if(!index || index<1 || index>total_page)
	{
		//alert("页码超出范围");
		return;
	}
	//向隐藏域中存入当前的页数
	document.getElementById('currentPage').value=index;
	update_page(total_page,index,'code',pagesize);
	callback(index,pagesize);
	
};


function next(a_html,pagesize,total_page)
{
	//alert("a_html=="+a_html+"  pagesize=="+pagesize+"  total_page=="+total_page);
	
	
	//从隐藏域中取页数
	var current_pageS=document.getElementById('currentPage').value;
	var current_page;
	if(parseInt(current_pageS)<total_page){
		current_page=parseInt(current_pageS)+1;
	}else{
		current_page=parseInt(current_pageS);
	}
	update_page(total_page,current_page,'code',pagesize);
	go(current_page,pagesize,total_page);
	
	//向隐藏域中存入当前的页数
	document.getElementById('currentPage').value=current_page;
	
	
};


function prev(a_html,pagesize,total_page)
{
	
	//从隐藏域中取页数
	var current_pageS=document.getElementById('currentPage').value;
	var current_page;
	if(parseInt(current_pageS)>1){
		current_page=parseInt(current_pageS)-1;
	}else{
		current_page=parseInt(current_pageS);
	}
	update_page(total_page,current_page,'code',pagesize);
	go(current_page,pagesize,total_page);	
	
	//向隐藏域中存入当前的页数
	document.getElementById('currentPage').value=current_page;	
	
};

 